package service

import (
	"context"
	__ "goods-server/basic/proto"
	"goods-server/handler/model"
)

// 商品添加
func (s *Server) GoodsCreate(_ context.Context, in *__.GoodsCreateReq) (*__.GoodsCreateResp, error) {
	var err error
	var goods model.Goods
	goods = model.Goods{
		GoodsName:  in.GoodsName,
		GoodsPrice: float64(in.GoodsPrice),
		GoodsImg:   in.GoodsImg,
		Status:     in.Status,
		Inventory:  in.Inventory,
	}

	err = goods.GoodsCreate()
	if err != nil {
		return &__.GoodsCreateResp{
			Msg:  "商品添加失败",
			Code: 500,
		}, nil
	}

	return &__.GoodsCreateResp{
		Msg:  "商品添加成功",
		Code: 200,
	}, nil

}

// 商品分类
func (s *Server) TypeGoods(_ context.Context, in *__.TypeGoodsReq) (*__.TypeGoodsResp, error) {
	//var err error
	//var c model.Classification
	//
	//c = model.Classification{
	//	GoodsId:   c.GoodsId,
	//	GoodsName: c.GoodsName,
	//	GoodsType: c.GoodsType,
	//}
	//
	////查询商品分类信息
	//err = c.TypeFind()
	//if err != nil {
	//	return &__.TypeGoodsResp{
	//		Msg:  "分类信息查询失败",
	//		Code: 200,
	//	}, nil
	//}
	////判断分类是否重复
	//if c.GoodsName == in.GoodsName {
	//	return &__.TypeGoodsResp{
	//		Msg:  "分类名称重复",
	//		Code: 200,
	//	}, nil
	//}
	//
	////完成分类
	//err = c.TypeCreate()
	//if err != nil {
	//	return &__.TypeGoodsResp{
	//		Msg:  "商品分类失败",
	//		Code: 500,
	//	}, nil
	//}

	//return &__.TypeGoodsResp{
	//	Msg:  "分类名称重复",
	//	Code: 400,
	//}, nil
	return &__.TypeGoodsResp{
		Msg:  "商品分类成功",
		Code: 200,
	}, nil
}

// 橱窗商品关联
func (s *Server) GoodsCorrelation(_ context.Context, in *__.GoodsCorrelationReq) (*__.GoodsCorrelationResp, error) {

	var err error
	var g model.Goods
	list, total, err := g.GoodsList(int(in.Page), int(in.PageSize))
	if err != nil {
		return nil, err
	}

	var good []*__.List

	for _, val := range list {
		good = append(good, &__.List{
			GoodsName:  val.GoodsName,
			GoodsPrice: float32(val.GoodsPrice),
			GoodsImg:   val.GoodsImg,
			Status:     val.Status,
			Inventory:  val.Inventory,
		})
	}

	return &__.GoodsCorrelationResp{
		Msg:      "成功",
		Code:     int64(total),
		GetList:  good,
		Username: "123456",
		TypeName: "洗浴",
	}, nil
}

// 橱窗商品关联
func (s *Server) GoodsStatus(_ context.Context, in *__.GoodsStatusReq) (*__.GoodsStatusResp, error) {

	//var err error
	//var g model.Goods
	//g = model.Goods{
	//	Id:     uint64(in.GoodsId),
	//	Status: in.Status,
	//}
	//err = g.GoodsUpdeate()
	//if err != nil {
	//	return &__.GoodsStatusResp{
	//		Msg:  "状态审核失败",
	//		Code: 500,
	//	}, nil
	//}

	return &__.GoodsStatusResp{
		Msg:  "状态审核成功",
		Code: 200,
	}, nil
}
